package cn.m3a1.creditsystem.controller;

import cn.m3a1.creditsystem.bean.SchoolSchedule;
import cn.m3a1.creditsystem.bean.User;
import cn.m3a1.creditsystem.service.SchoolScheduleService;
import cn.m3a1.creditsystem.service.TrainingPlanService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author wyj
 * @date 2020/2/13
 * @time 下午12:28
 */
@Controller
public class SchoolScheduleController {
    @Autowired
    SchoolScheduleService scheduleService;
    @Autowired
    TrainingPlanService trainingPlanService;
    @GetMapping(value = "/getSchoolSchedule")
    @ResponseBody
    public PageInfo getSchoolSchedule(@RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "10") int pageSize,SchoolSchedule schedule,HttpServletRequest request){

        HttpSession session = request.getSession();
        User loginUser = (User) session.getAttribute("loginUser");
        if (loginUser == null) {
            return null;
        }

        PageHelper.startPage(pageNo, pageSize);
        List<SchoolSchedule> schoolSchedules = scheduleService.selectSchool(schedule);
        PageInfo pageInfo = new PageInfo(schoolSchedules);
        if (schedule.getTeacherId()!=null){
            System.out.println(schedule.getTeacherId());
        }
        return pageInfo;
    }

}
